/**
 * 员工职级管理
 */
app.controller('btnCtrl', ['$scope', '$http', BtnController]);
function BtnController($scope, $http){

    $scope.bindBtn = function(event) {
        var datas = $scope.getSelectedRows();
        switch(event){
            case 'event-to-add':
            {
                window.top.add_tab('员工职级管理 - 新增', '/web/base/tbUserJobLevelManage/toAdd');
                break;
            }
            case 'LAYTABLE_EXPORT_DATA':
            {
                $scope.doExport('/api/inter/tbUserJobLevelManage/export');
                break;
            }
            case 'event-to-edit'://编辑
            {
                if(datas.length == 0) {
                    layer.alert('尚未选中数据');
                } else if(datas.length > 1) {
                    layer.alert('只能选中一行数据');
                } else {
                    window.top.add_tab('员工职级管理 - 编辑', '/web/base/tbUserJobLevelManage/toEdit?id=' + datas[0].id);
                }
                break;
            }
            case 'event-to-push'://薪资绩效推送
            {
                if(datas.length == 0) {
                    layer.alert('尚未选中数据');
                } else {
                    layer.open({
                        shadeClose:true,
                        title: '选择绩效月份',
                        content: `
								<form class="layui-form">
								  <div class="layui-form-item">
									 <input type="text" class="layui-input" id="tbUserJobLevelManage_choose_month" placeholder="选择绩效月份">
								  </div>
								</form>
							`,
                        success: function(layero, index) {},
                        yes: function (index, layero) {
                            var chooseMonth = $('#tbUserJobLevelManage_choose_month').val();
                            if(chooseMonth==undefined || chooseMonth==null || chooseMonth==''){
                                layer.alert('请选择绩效月份！');
                                return;
                            }
                            //layer.closeAll();
                            layer.msg('处理中', { icon: 16, shade: 0.01 });
                            var ids = '';
                            for(var i=0;i<datas.length;i++){
                                if(ids==''){
                                    ids = datas[i].id;
                                }else {
                                    ids = ids + ',' +datas[i].id;
                                }
                            }
                            $http.post('/api/inter/tbUserJobLevelManage/pushToMonthPerformance', {}, {params: {ids: ids,chooseMonth:chooseMonth}})
                                .success(function (data) {
                                    if (data.code == 0) {
                                        layer.msg(data.msg);
                                        setTimeout(function(){
                                            layer.closeAll();
                                        }, 1000);
                                    } else {
                                        layer.msg(data.msg);
                                        layer.closeAll();
                                    }
                                })
                                .error(function(result){
                                    layer.close();
                                    layer.msg("操作失败，请稍后再试！", {icon: 2});
                                });
                        }
                    });
                    layui.use(function(){
                        var laydate = layui.laydate;
                        // 年月选择器
                        laydate.render({
                            elem: '#tbUserJobLevelManage_choose_month',
                            type: 'month'
                        });
                    });
                }
                break;
            }

        };
    }
}


//表格双击
app.controller('dbClickCtrl', ['$scope', '$http', DbClickController]);
function DbClickController($scope, $http){
    $scope.doubleClick = function(data) {
        window.top.add_tab('员工职级管理 - 详情','/web/base/tbUserJobLevelManage/toDetail?id=' + data.id);
    }
}

